﻿using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using GitNet.WindowsApp.ViewModels;

namespace GitNet.WindowsApp.AddViews;

public partial class AddTagView : UserControl
{
    private readonly string sha;
    public AddTagView()
    {
        InitializeComponent();
        sha = "";
    }

    public AddTagView(string sha)
    {
        InitializeComponent();
        this.sha = sha;
    }

    private void InitializeComponent()
    {
        AvaloniaXamlLoader.Load(this);
    }

    private void OkClick(object? sender, RoutedEventArgs e)
    {
        if(Parent?.DataContext is not RepositoryViewModel model)return;
        if(string.IsNullOrEmpty(TagNameBox.Text) || string.IsNullOrEmpty(sha))return;
        model.AddTag(sha,TagNameBox.Text,PointingBox.Text);
    }
}